
if (!jsx3.lang.Class.forName("ux.cdb.admin.system.user.userManage.userWizard.UserInfo")) {
  jsx3.lang.Class.defineClass("ux.cdb.admin.system.user.userManage.userWizard.UserInfo", ux.megatron.gui.WizardPanel, null, function(block){
    /**
     * instance initializer
     * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
     * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
     */
    block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML){
      //call constructor for super class (the super expects the name of the object and the function that it is an instance of)
      this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
    };
    block.changeValue=false;
    block.prototype.initialize = function(msg){
       //ux.megatron.Main.loadClass("ux/cdb/admin/CommonCache.js","ux.cdb.admin");
       this.wizard = this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard");
       this.userInfo = this.get("blkUserInfo");
       var me = this;
	   
		var cache = ux.cdb.admin.CommonCache.getInstance();
		var USER_TYPE_CDF = cache.getCache('CommonCache_SYSTEM_USER');

		var __user_type = ux.cdb.admin.system.user.UserManage.USER_TYPE;
		var __user_type_box = me.get('usertypecode').getChild(1);
		if(__user_type == 0){//总行
			USER_TYPE_CDF.deleteRecord('2');
		}else if(__user_type == 1){//分行
		}else if(__user_type == 2){//合作机构
			this.get('fieldOfLogonName').hide();
			USER_TYPE_CDF.deleteRecord('1');
		}
		if(__user_type > -1){
			__user_type_box.setSourceXML(USER_TYPE_CDF);
			__user_type_box.repaint();
		    /* @JSC :: begin DEBUG */
			console.log('__user_type : ',__user_type);
			console.log('USER_TYPE_CDF',USER_TYPE_CDF);
			/* @JSC :: end */
		}
		
		if(me.wizard.Operation=="Edit"){
           //set the data when edit the personal inf.
           var sysUserId=ux.megatron.Main.getServer().getJSXByName("sysUserId");
           sysUserId.setDisplay(jsx3.gui.Block.DISPLAYBLOCK,true);
           sysUserId.getDescendantOfName("txtValue").setEnabled(jsx3.gui.Form.STATEDISABLED,true);
		   this.get('fieldOfLogonName').get('txtValue').disable();
		   
           var data = ux.cdb.admin.system.user.UserManage.UserInfoReqUIO;
           var gdobj = ux.megatron.Main.getServer().getJSXByName("blkUserInfo");
           gdobj.setDataByObject(data);
           gdobj.refreshData();
       }
       else if(me.wizard.Operation=="Insert"){
              var buttonFinish=ux.megatron.Main.getServer().getJSXByName("buttonFinish");
              buttonFinish.setDisplay(jsx3.gui.Block.DISPLAYNONE,true);
        }
         var CERT_TYPE_CDF=cache.getCache('CommonCache_CERT_TYPE');
         me.get('certType').getChild(1).setSourceXML(CERT_TYPE_CDF);
         me.get('certType').getChild(1).repaint();
    };
    
    block.prototype.callBackDwr = function(data){
    };
	
    block.prototype.validate=function(){
          //var result =  this.get("blkUserInfo").doValidate();
			var errorMsgs = this.get("blkUserInfo").doValidate();
			this._message = errorMsgs === null ? null : (errorMsgs[0].label ? errorMsgs[0].label + " : " +errorMsgs[0].message : errorMsgs[0].message);
          if(errorMsgs != null){
             return false;  //  illegal
          }else{
             return true;  //legal
          }
    };
	
    block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
    try{
           var lbl = this.wizard.get("lblMessage");
           var cert_cmm = this.get('certType');
           if(cert_cmm.extractData()==1||cert_cmm.extractData()==2){ 
               this.get('fieldOfCertCode').setValidator("Required,IDCard");
           }else{
               this.get('fieldOfCertCode').setValidator("Required");
		   }
          if(!this.validate()){
               var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@userInfovalidate");
              lbl.setText(this._message ? this._message : tip, true);
              return 'NONE';
          }else{
              if(this.wizard.Operation=="Insert"){
                 var gdobj=ux.megatron.Main.getServer().getJSXByName("blkUserInfo");
                 var userinf=gdobj.getDataAsObject();
                 for(element in userinf){
                     ux.cdb.admin.system.user.UserManage.UserInfoReqUIO[element]=userinf[element];
                 }
              }else{
                   this.modified();
              }
             lbl.setText('',true);
        }
        return null; // return "NONE" to not next panels
      }catch(ex){
             jsx3.lang.Exception.printStackTrace();
      }
    }

    block.prototype.checkInput = function() {
      return true;
    }

    block.prototype.setInputData = function() {
      /*private String userName;
        private String logonName;
        private String logonPwd;
        private String userRelatedOrg;
        private String userStatusIndicator;
        private String userDesc;
        private String systemUserTypeCode;
        private String certTypeCode;
        private String certId;
        private List<SysRole> selectRoleList;
        ownedDepartmentCode
        ownedDepartmentName
      */
      var cdf = this.userInfo.getData();
      if(this.wizard.userInfoCDF) delete this.wizard.userInfoCDF;
      this.wizard.userInfoCDF = cdf;
    }

    block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
      return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
      return null; // return "NONE" to not last status
    }
    
    block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
      this.wizard.onClose();
      return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
      return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL){
      if (!this.getChild(0)) {
        var me = this;
        ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin", "ux/cdb/admin/system/user/userWizard/step1/ui/UserInfoContent.xml", me, me.initialize);
      }
      return null; // return "NONE" to not advance panels
    }
    /*@
    *@
    @*/
    block.prototype.onStepJump=function(objWIZARD, objSTEP, objEVENT, strCURRENTPANEL){
       /* var lbl = this.wizard.get("lblMessage");
          if(!this.validate()){
              var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@userInfovalidate");
              
              lbl.setText(tip,true);
              return 'NONE';
          }else{
             /*var gdobj=ux.megatron.Main.getServer().getJSXByName("blkUserInfo");
             var userinf=gdobj.getDataAsObject();
             for(element in userinf){
                 ux.cdb.admin.system.user.UserManage.UserInfoReqUIO[element]=userinf[element];
             }
             var gd=this.wizard.get("blkUserInfo");
            // var gd=ux.megatron.Main.getServer().getJSXByName("blkUserInfo");
            var userinf=gd.getDataAsObject();
            var userInfoReqUIO=ux.cdb.admin.system.user.UserManage.UserInfoReqUIO;
            for(element in userinf){
                if(userinf[element]==""){
                 userinf[element]=null;
                }
                if(userInfoReqUIO[element]!=userinf[element]){
                    userInfoReqUIO[element]=userinf[element];
                    ux.cdb.admin.system.user.UserManage.Userchanged=true;
                }
             }
             console.log("step1 value changed:"+ux.cdb.admin.system.user.UserManage.Userchanged);
             lbl.setText('',true);
             return null;
         } */
        return this.onNext();
    }

    block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
        var me=this;
        var lbl = this.wizard.get("lblMessage");
          if(this.validate()){
                 if(this.wizard.Operation=="Edit"){
                           lbl.setText('',true);
                           /* @JSC :: begin DEBUG */
                           console.log("step1 finish start");
                           /* @JSC :: end */
                           if(this.modified()||ux.cdb.admin.system.user.UserManage.Orgchanged||ux.cdb.admin.system.user.UserManage.Rolechanged){
                               ux.megatron.util.Dwr.callDwr("UserMgrUCC", "updateUserInfo", [ux.cdb.admin.system.user.UserManage.UserInfoReqUIO], this, function(dwrobj){
                                   if(dwrobj!=null){
                                       if(dwrobj.res.flag=="1"){
                                           //me.wizard.onClose();
                                           ux.cdb.admin.Cache.remove(ux.cdb.admin.dataautomate.GenericDetail.User+":"+ux.cdb.admin.system.user.UserManage.UserInfoReqUIO.sysUserId);
                                           var um=ux.megatron.Main.getServer().getJSXByName("blkWorld");
                                           um.LoadUsers();
                                           return;
                                       }
                                   }
                               //add some code to catch exception when save
                                }, "UserMgrUCC");
                             //ux.megatron.Dialog.alert();
                           }
                           this.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
                   }else{
                       ux.cdb.admin.system.user.userManage.userWizard.UserInfo.stepCheck(lbl,this);
                   }
          }else{
             var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step1@unfinish");
             
             lbl.setText(tip,true);
          }
    }
    /*@
    *    this function is used to check step2 and step3 validate. 
    *    me: context
    *    just for saves
    @*/
    block.stepCheck=function(lbl,me){
         var mxorg=me.wizard.get("mtxOrgSelect");
         var um=ux.megatron.Main.getServer().getJSXByName("blkWorld");
          if(mxorg){   //check step 2
               if(mxorg.getSelectedNodes().size()==0&&me.wizard.Operation=="Insert"){
                      var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step2@unfinish");
                      
                      lbl.setText(tip,true);
                }else{   //check step 3
                     var mxRole=me.wizard.get("mtxSel");
                     var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step3@unfinish");
                     if(mxRole){
                          if((mxRole.getXML().getChildNodes().size()==0)){
                            
                            lbl.setText(tip,true);
                          }else{  //step3 finish button
                                  var it=mxRole.getXML().getChildNodes().iterator();
                                  var SysRolelist=[];
                                  while(it.hasNext())
                                  {
                                      var role=new Object();
                                      var item=it.next();
                                      role.roleName=item.getAttribute("roleName");
                                      role.sysRoleId=parseInt(item.getAttribute("jsxid"));
                                      role.parentRoleId=isNaN(parseInt(item.getAttribute("parentRoleId")))?0:parseInt(item.getAttribute("parentRoleId"));
                                      role.roleType=null;
                                      role.roleDesc=item.getAttribute("roleDesc");
                                      SysRolelist.push(role);
                                  }
                                  //var gdobj=ux.megatron.Main.getServer().getJSXByName("blkUserInfo");
                                  var userInfoUIO=ux.cdb.admin.system.user.userManage.userWizard.UserInfo.getUserInf(SysRolelist);
                                   /* @JSC :: begin DEBUG */
                                  console.log(ux.cdb.admin.system.user.UserManage.UserInfoReqUIO);
                                  /* @JSC :: end */
                                   ux.megatron.util.Dwr.callDwr("UserMgrUCC", "addUserCommon"/* "addUserAndRoleInfo" */, [userInfoUIO], this, function(dwrobj){
									   if(dwrobj.res.flag=="1"){
										  um.LoadUsers();
										  /* @JSC :: begin DEBUG */
										  jsx3.log("[addUserCommon][success]:"+userInfoUIO);
										  /* @JSC :: end */
										}else{
										  /* @JSC :: begin DEBUG */
											 jsx3.log("[addUserCommon][failed]:"+userInfoUIO);
										  /* @JSC :: end */
										}
	                                  me.getAncestorOfType("ux.cdb.admin.system.user.userManage.UserWizard").onClose();
                                  }, "UserMgrUCC");
                          }
                      }else{
                               
                               lbl.setText(tip,true);
                      }
                }
          }else{
                var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@System@UserManage@UserWizard@step2@unfinish");
                
                lbl.setText(tip,true);
          }
    }
    block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL){
      return null; // return "NONE" to not advance panels
    }

    block.onAfterDeserialize=function(){
        //alert("onAfterDeserialize");
    }
    block.prototype.checkChangeValue = function(recordId){
		block.changeValue=true;
		/* @JSC :: begin DEBUG */
		 console.log("UserInfo#checkChangeValue begin... recordId : " + recordId);
		 /* @JSC :: end */
		if(recordId){
			var fieldOfLogonName = this.get('fieldOfLogonName');
			if(recordId == 1){
				fieldOfLogonName.setValidator("Required");
				fieldOfLogonName.getChild(1).enable();
				fieldOfLogonName.getChild(2).show();
			}else if(recordId == 2){
				fieldOfLogonName.setValidator("");
				fieldOfLogonName.doValidate();
				fieldOfLogonName.getChild(1).disable();
				fieldOfLogonName.getChild(2).hide();
			}
		}
    }
    block.getUserInf=function(){
        try{
                /* @JSC :: begin DEBUG */
                 console.log("[getUserInf][start]");
                 /* @JSC :: end */
                 var userInfoReqUIO=ux.cdb.admin.system.user.UserManage.UserInfoReqUIO;
                 userInfoReqUIO["selectRoleList"]=arguments[0];
                /* @JSC :: begin DEBUG */
                 console.log("[getUserInf][end]");
                 /* @JSC :: end */
                return userInfoReqUIO;
        }catch(ex){
            jsx3.log(ex);
        }
        return null;
    }
/*@
 *   when edit , check weather modified.
@*/
    block.prototype.modified=function(){
                /* @JSC :: begin DEBUG */
        console.log("modified start");
                 /* @JSC :: end */
         var gd=ux.megatron.Main.getServer().getJSXByName("blkUserInfo");
         var userinf=gd.getDataAsObject();
         var userInfoReqUIO=ux.cdb.admin.system.user.UserManage.UserInfoReqUIO;
         for(element in userinf){
             if(userinf[element]==""){
                 userinf[element]=null;
             }
             if(userInfoReqUIO[element]!=userinf[element]){
                ux.cdb.admin.system.user.UserManage.UserInfoReqUIO[element]=userinf[element];
                ux.cdb.admin.system.user.UserManage.Userchanged=true;
             }
         }
         //window.top.demo=ux.cdb.admin.system.user.UserManage.UserInfoReqUIO;
                /* @JSC :: begin DEBUG */
         console.log(ux.cdb.admin.system.user.UserManage.Userchanged);
                 /* @JSC :: end */
         return ux.cdb.admin.system.user.UserManage.Userchanged

     }
  });
}
